package com.compass;

import android.content.Context;
import android.content.SharedPreferences;

import com.activity.MyApplicationMainActivity;
import com.commun.Param;
import com.commun.Utils;

public class Settings {
	private Double lat;
	private Double lon;

	private Context context;

	public static int test = 0;

	private static Settings instance;
	private static double qibla_Lat = 21.4225, qibla_Lon = 39.826111;

	public static Settings getInstance(Context context) {
		if (instance == null)
			instance = new Settings(context);
		return instance;
	}

	private Settings(Context context) {
		this.context = context;

		lat = MyApplicationMainActivity.mLatitude;
		lon = MyApplicationMainActivity.mLongitude;

	}

	public void reset() {
		SharedPreferences param = this.context.getSharedPreferences(
				Param.APPLICATION_NAME, 0);
		param.edit().clear().commit();
	}

	public double getLat() {
		return lat;
	}

	public double getLon() {
		return lon;
	}

	public float getDegQibla() {
		double rlng = Utils.deg2rad(qibla_Lon - this.getLon());
		return Utils.rad2deg(Math.atan2(Math.sin(rlng), Math.cos(Utils
				.deg2rad(this.getLat()))
				* Math.tan(Utils.deg2rad(qibla_Lat))
				- Math.sin(Utils.deg2rad(this.getLat())) * Math.cos(rlng)));
	}

	public static double getQibla_Lat() {
		return qibla_Lat;
	}

	public static double getQibla_Lon() {
		return qibla_Lon;
	}

}